
from includes import *

from State import *
from loadState import *
from Galaxy import *
from drawGalaxy import *

# include Gui stuff
from Gui.Gui import *
from Gui.GuiToolbar import *
from Gui.GuiBtn import *
from MainGameGui import *

# This class is the state that will start a new game. 
class gameState(State):
	# string containing the name of the state
	
	# Constructor for the game state, put all init here.
	def __init__(self):
		State.__init__(self)
		self.name="gameState()"
		
		# TODO impliment  zoom function on the galaxy view
		self.zoom = 1
		
		# TODO offsets to move the map around when it is zoomed.
		self.offsetX = 0
		self.offsetY = 0
		
		# Change needsInit as this is the init.
		self.needsInit = 0
		
		# get the pygame screen
		self.screen = pygame.display.get_surface()
		
		# generate a new galaxy
		self.galaxy = Galaxy(20,20,3)
		# new Gui object, make a window and add it to the list
		# to be drawn.
		self.gui = Gui()
		mgGui = MainGameGui(self.gui, self.galaxy)
		
	def update(self):
		mpos = pygame.mouse.get_pos()
		for e in pygame.event.get():
			if e.type is QUIT: 
				self.run = 0
			if e.type is KEYDOWN and e.key == K_ESCAPE: 
				self.run = 0
			if e.type is MOUSEBUTTONUP: 
			
				# TODO: will need a change when getClick gets refactored.
				clicked = self.gui.getClick(mpos[0], mpos[1])
				# print clicked  #returns the GuiObject that was clicked.
				
				# After a click is detected, checks to see if there is an event on the queue (or multiple)
				# and fires it (them)
				if clicked:
					#print clicked
					if clicked.onClick:
						for event in clicked.onClick:
							event(clicked, self.gui)
		# Run the update method on the Gui.
		self.gui.update()

	def draw(self):
		galaxyS = drawGalaxy(self.galaxy, self.galaxy.stars, 1, 1, 600, 600)
		pygame.draw.rect(self.screen, (0, 0, 0), Rect(0, 0, 1024, 768), 0)
		self.gui.draw()
		# self.screen.blit(galaxyS, (20, 15, 600, 600))
		pygame.display.flip()
